package Controller

import (
	"github.com/gin-gonic/gin"
	"selfService/ginWeb/Service"
	"selfService/tool"
	"selfService/兴趣相关/service/interest"
)


var InterestService Service.InterestService

// // 获得所有兴趣选项（管理员）
func PersionInterest(c *gin.Context)  {
	result,err:= InterestService.GetProdStockClient()
	if err!=nil {
		tool.Failed(c,err)
	}
	tool.Success(c,result)
}


// // 添加兴趣（管理员）
func AddInterest(c *gin.Context)  {
	request:=&interest.Interest{}
	request.InterestName = c.PostForm("interest")
	request.Id=tool.GenerateID()
	result,err := InterestService.InsertInterest(request)
	if err != nil{
		tool.Failed(c,"失败")
		return
	}
	if result =="失败"{
		tool.Failed(c,"失败")
		return
	}
	tool.Success(c,"添加成功")

}

// 根据id 修改兴趣选项（管理员端）
func ChangeTheInterest(c *gin.Context)  {
	id := c.Query("id")
	ChangeName := c.Query("changeName")
	request := &interest.InterestRequest{
		Id: id,
		ChangeName: ChangeName,
	}
	rest,err := InterestService.ChangeInterest(request)
	if err!=nil {
		tool.Failed(c,"失败")
		return
	}else {
		tool.Success(c,rest)
	}

}

// 根据id  删除某个兴趣（管理员）
func DeleteInterestById(c *gin.Context)  {
	id := c.Param("id")
	result,err :=InterestService.DeleteInterestById(&interest.UserInterMidRquest{
		Id: id,
	})
	if err !=nil {
		tool.Failed(c,"失败")
		return
	}
	if result =="失败" {
		tool.Failed(c,"失败")
		return
	}else {
		tool.Success(c,result)
		return
	}

}
// ---------------------------------------------------------------------------------------------------------
// 获得个人兴趣列表
func PersionInterestSelf(c *gin.Context)  {
	id := c.Param("id")
	result,err:= InterestService.GetMyselfInterest(id)
	if err!=nil {
		tool.Failed(c,err)
	}
	tool.Success(c,result)
}

//根据id 修改个人兴趣选项
func ChangeInterest(c *gin.Context)  {
	id := c.Param("id")
	Changeid := c.Param("Changeid")
	result:= InterestService.ChangeSelfInterest(id,Changeid)
	if result == "成功" {
		tool.Success(c,result)
	}else {
		tool.Failed(c,result)
	}
}

// 根据id 删除自己的某个兴趣选项
func DeleteSelfInterestById(c *gin.Context)  {
	id := c.Param("id")
	result := InterestService.DeleteSelfInterestById(id)

	if result =="失败" {
		tool.Failed(c,"失败")
		return
	}else {
		tool.Success(c,result)
		return
	}

}

//添加兴趣
func InsertSelfInterest(c *gin.Context)  {
	userId := c.PostForm("userId")
	interId := c.PostForm("interId")
	result:=InterestService.InsertSelfInterest(userId,interId)
	if result == "成功" {
		tool.Success(c,result)
	}else {
		tool.Failed(c,result)
	}
}
